package com.njh.tools.common.userInfo;

import android.content.Context;

import com.apkfuns.logutils.LogUtils;
import com.njh.tools.common.Utils;
import com.njh.tools.common.sp.SP;



/**
 * Created by fly on 2016/11/14.
 */

public class SPUserInfo {
    /**
     * "province":"1",
     "city":"36",
     "industry":"3",
     "token":"V3LGXPIMRe3TRFLCRX30450nQrEGVa6qSGwqW53nYv7q1IsIflIYfHCvyG2Kgx1z",
     "terminalNo":"1",
     "provincename":"北京",
     "cityname":"东城",
     "industryname":"硬件"
     */
    static {
        SP.FILE_NAME = "Member";
    }

    public static String getNickname(Context context){
        return (String) SP.get(context,NICKNAME,"");
    }
    public static void setNickname(Context context, String nickname) {
        SP.put(context, NICKNAME, nickname);
    }

    public static boolean getIsLogin(Context context){
        return (boolean) SP.get(context,ISLOGIN,false);
    }
    public static void setIsLogin(Context context,boolean isLogin){
         SP.put(context,ISLOGIN,isLogin);
    }
    public static String getUid(Context context){
        return (String) SP.get(context,UID,"");
    }
    public static void setUid(Context context, String id) {
        SP.put(context, UID, id);
    }

    public static String getUserId(Context context) {
        return (String) SP.get(context,USER_ID,"");
    }
    public static void setUserId(Context context,String userId) {
        SP.put(context,USER_ID,userId);
    }
    public static String getPhone(Context context){
        return (String) SP.get(context,PHONE,"");
    }
    public static void setPhone(Context context, String phone) {
        SP.put(context, PHONE, phone);
    }

    public static String getToken(Context context) {
        return (String) SP.get(context,TOKEN,"");
    }
    public static void setToken(Context context,String Phone) {
        SP.put(context,TOKEN,Phone);
    }
    public static String getHeadurl(Context context) {
        return (String) SP.get(context,HEADURL,"");
    }
    public static void setHeadurl(Context context,String headurl) {
        SP.put(context,HEADURL,headurl);
    }
    public static String getBalance(Context context) {
        return (String) SP.get(context,BALANCE,"");
    }
    public static void setBalance(Context context,int Balance) {
        SP.put(context,BALANCE,Balance);
    }
    public static String getRestertime(Context context) {
        return (String) SP.get(context,RESTERTIME,"");
    }
    public static void setRestertime(Context context,String userId) {
        SP.put(context,RESTERTIME,userId);
    }
    public static void setAutonym(Context context,String autonym){
        SP.put(context,AUTONYM,autonym);
    }
    public static String getAutonym(Context context){
        return (String) SP.get(context,AUTONYM,"");
    }
    public static void save(Context context, UserInfoBean model) {
        LogUtils.e(SP.FILE_NAME);
        setUid(context, Utils.checkNull(model.getUid()));
        setNickname(context, Utils.checkNull(model.getNickname()));
        setPhone(context, Utils.checkNull(model.getPhone()));
        if (model.getHeadurl()!=null) {
            setHeadurl(context, Utils.checkNull(model.getHeadurl()));
            //setPHOTOID(context, Utils.checkNull(model.getPhoto().getId()));
        }
        setUserId(context,Utils.checkNull(model.getUser_id()));
        setToken(context, Utils.checkNull(model.getToken()));
        setRestertime(context, Utils.checkNull(model.getRestertime()));
        setBalance(context, model.getBalance());
    }

    private static final String PHONE="phone";
    private static final String USER_ID="user_id";
    private static final String UID="uid";
    private static final String NICKNAME="nickname";
    private static final String TOKEN="token";
    private static final String HEADURL="headurl";
    private static final String BALANCE="balance";
    private static final String RESTERTIME="restertime";
    private static final String ISLOGIN="islogin";//是否登录
    private static final String AUTONYM="autonym";//实名认证
    public static void clear(Context context) {
        LogUtils.e(SP.FILE_NAME);
        SP.clear(context);
    }
}
